package com.dailyblue.java.spring.rocketmq.延迟消息;

import com.dailyblue.java.spring.rocketmq.util.DateUtil;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class 延迟消息的生产 {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("zhuoyue01");
        producer.setNamesrvAddr("192.168.160.88:9876");
        producer.start();
        System.out.println(DateUtil.getNowDate()+"开始生产了10条消息");
        for (int i = 1; i < 11; i++) {
            String topic = "TopicA";
            String tags = "yanchi1";
            String body = "Yanchi，index:" + i + ",time:" + DateUtil.getNowDate();
            Message message = new Message(topic, tags, body.getBytes(StandardCharsets.UTF_8));
            message.setDelayTimeLevel(3);
            SendResult result = producer.send(message);
            System.out.println(result);
        }
        System.out.println(DateUtil.getNowDate()+"生产了10条消息");
        producer.shutdown();
    }
}
